package com.xiaotu.service.common.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.xiaotu.dao.common.ContactUsMapper;
import com.xiaotu.model.ContactUsModel;
import com.xiaotu.service.common.ContactUsService;
import com.xiaotu.vo.ContactUsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.List;

/**
 * @author zhangxiao
 * @create 2021-09-03 11:47
 */
@Service
@Transactional
public class ContactUsServiceImpl implements ContactUsService {

    @Autowired
    private ContactUsMapper contactUsMapper;

    @Override
    public Collection<ContactUsVo> getContactUs() {
        Example example = new Example(ContactUsModel.class);
        example.selectProperties("usTitle", "usContent");
        example.orderBy("sort").asc();
        return CollectionUtil.trans(contactUsMapper.selectByExample(example), s -> {
            ContactUsVo contactUsVo = new ContactUsVo();
            BeanUtil.copyProperties(s, contactUsVo);
            return contactUsVo;
        });
    }
}
